package com.zhoukx.demeter.improve;

import java.util.ArrayList;
import java.util.List;


public class Demeter1 {

	public static void main(String[] args) {
		System.out.println("使用迪米特法则");
		SchoolManager schoolManager = new SchoolManager();
		schoolManager.printAllEmployee(new CollegeManager());

	}

}


//学校总部 员工
class Employee {
	private String id;

	public void setId(String id) {
		this.id = id;
	}

	public String getId() {
		return id;
	}
}


//学院的员工
class CollegeEmployee {
	private String id;

	public void setId(String id) {
		this.id = id;
	}

	public String getId() {
		return id;
	}
}


//管理学院员工类
class CollegeManager {
	//返回学院所有的员工
	public List<CollegeEmployee> getAllEmployee() {
		List<CollegeEmployee> list = new ArrayList<CollegeEmployee>();
		for (int i = 0; i < 10; i++) {
			CollegeEmployee emp = new CollegeEmployee();  //这里我们增加了10个员工到list
			emp.setId("学院员工IDid= " + i);
			list.add(emp);
		}
		return list;
	}

	// 输出学院员工的信息
	public void printEmployee(){
		List<CollegeEmployee> list1 = this.getAllEmployee();
		System.out.println("-----------------学院员工-------");
		for (CollegeEmployee e : list1) {
			System.out.println(e.getId());
		}
	}
}

// 学校管理类
//CollegeManager
class SchoolManager {
	//返回学校总部的员工
	public List<Employee> getAllEmployee() {
		List<Employee> list = new ArrayList<Employee>();

		for (int i = 0; i < 5; i++) { //这里添加5个员工
			Employee emp = new Employee();
			emp.setId("学校总部员工id= " + i);
			list.add(emp);
		}
		return list;
	}

	//该方法完成输出学校总部和学院员工的信息
	void printAllEmployee(CollegeManager sub) {

		//分析问题
		// 1 将输出学院的员工方法，封装到collegeManger中
        sub.printEmployee();
		//学校总部的员工
		List<Employee> list2 = this.getAllEmployee();
		System.out.println("------------总部的员工------------");
		for (Employee e : list2) {
			System.out.println(e.getId());
		}
	}
}
